package com.emcom.gotour.mvc.model;

import java.util.ArrayList;
import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.springframework.context.MessageSource;

import com.emcom.gotour.enums.TourType;
import com.emcom.gotour.mvc.message.CategoryViewMessage;
import com.emcom.gotour.mvc.view.CategoryContentView;
import com.emcom.gotour.mvc.view.CategoryView;
import com.emcom.gotour.mvc.view.GlobalView;
import com.emcom.gotour.mvc.view.NavigationView;
import com.emcom.gotour.po.TourCategory;
import com.emcom.gotour.service.TourCategoryService;

public class TourCategoryModel {
	public static String PAGING_NAME = "CATEGORY";
	public static void getView(HttpServletRequest request, MessageSource messageSource, TourCategoryService tourCategoryService, String typeId) {
		CategoryView view = new CategoryView();
		view.setTitle(CategoryViewMessage.Title.value(request, messageSource));
		List<TourCategory> categoryList = new ArrayList<TourCategory>();
		List<TourCategory> tourCategoryList = tourCategoryService.query(typeId);
		for(TourCategory tourCategory : tourCategoryList) {
			tourCategory.setTypeId(TourType.valueOf(tourCategory.getTypeId()).value());
			categoryList.add(tourCategory);
		}
		view.setCategoryList(categoryList);
		view.setNavigationView(new NavigationView(request, messageSource));
		view.setCategoryContentView(new CategoryContentView(request, messageSource));
		view.setGlobalView(new GlobalView(request, messageSource));
		request.setAttribute("view", view);
	}
}
